package cn.middle.edge.portal;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.middle.common.result.ApiResponse;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.middle.edge.entity.EdgePark;
import cn.middle.edge.service.EdgeParkService;

/**
 * 园区信息
 * @author KING
 *
 */
@Controller
@RequestMapping("/edgePark")
public class EdgeParkController {
	
	@Autowired
	private EdgeParkService edgeParkService;
	
	@SaCheckPermission("edge:abount")
	@GetMapping("/about")
	public String about(ModelMap modelMap) {
		EdgePark park = edgeParkService.theOne();
		modelMap.put("model",  park != null ? park : new EdgePark());
		return "base-configuration";
	}
	
	@SaCheckPermission("edge:abount")
	@ResponseBody
	@PostMapping("/update")
	public ApiResponse<String> updateAndSave(@Valid EdgePark park){
		if(park.getId() == null) {
			edgeParkService.save(park);
		}else {
			EdgePark sysPark = edgeParkService.getById(park.getId());
			if(sysPark != null) {
				this.edgeParkService.update(park);
			}else {
				edgeParkService.save(park);
			}
		}
		
		return ApiResponse.successWithData("更新成功！");
	}
	
	

}
